﻿using AllanXingCommonLibrary;
using cnBlogs.Common;
using cnBlogs.DataModel;
using cnBlogs.Model;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace cnBlogs.ViewModel
{
    public class ArticleDetailViewMoel : GetFeedsBase
    {
        private ArticleDetailModel _ArticleDetailInfo = new ArticleDetailModel();

        public ArticleDetailModel ArticleDetailInfo
        {
            get { return _ArticleDetailInfo; }
            private set
            {
                this.SetProperty(ref _ArticleDetailInfo, value);
            }
        }

        private ArticleInfo _articleInfo;

        public ArticleDetailViewMoel(ArticleInfo articleInfo)
        {
            _articleInfo = articleInfo;
        }

        protected override void Parse(string feed)
        {
            GroupCollection gpcontant = Regex.Match(feed, "<div id=\"cnblogs_post_body\">(?<Contant>.*?)</div><div id=\"MySignature\">").Groups;
            GroupCollection gptitle = Regex.Match(feed, "<a.*?(id=\"cb_post_title_url\")?(id=\"ctl01_lnkTitle\")?.*?href=\"" + _articleInfo.Link + "\">(?<Title>.*?)</a>").Groups;
            ArticleDetailModel adm = new ArticleDetailModel();
            adm.ArticleContent = gpcontant["Contant"].Value;
            adm.ArticleTitle = gptitle["Title"].Value;
            _ArticleDetailInfo=adm;
        }

        protected override string GetUrl()
        {
            return _articleInfo.Link;
        }
    }
}
